import 'dart:convert';


import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '/kong.dart' if (dart.library.io) 'package:osg/middleware/im_manager.dart';

import '/kong.dart' if (dart.library.io) 'package:tencent_cloud_chat_sdk/models/v2_tim_user_full_info.dart';

class CommunicationLIst extends StatefulWidget {
  const CommunicationLIst({super.key});
  @override
  State<CommunicationLIst> createState() => _CommunicationLIst();
}

class _CommunicationLIst extends State<CommunicationLIst> {
  final TextEditingController controller = TextEditingController();

    
   final RxList<V2TimUserFullInfo> list = <V2TimUserFullInfo>[].obs;
  //RxList list=[].obs;

  Future<void> _getFriendList() async {
    list.value = await ImManager().getFriendList();

    print(11111);
     
  }

  void _search(String keyword) {
    // 在这里实现搜索逻辑，例如打印关键词
    print('搜索关键词: $keyword');
    // 可以在这里调用API或过滤数据等
  }

  @override
  void initState() {
    super.initState();

    _getFriendList();
  }

  @override
  void dispose() {
    controller.dispose();

    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final totalHeight = MediaQuery.of(context).padding.top + 15;
    return Scaffold(
      body: Stack(
        children: [
          ListView(
            padding:
                EdgeInsets.only(top: totalHeight + 35, left: 15, right: 15),
            children: [
              Stack(
                children: [
                  Container(
                    alignment: Alignment.center,
                    height: 40,
                    child: TextField(
                      onChanged: (value) {
                        print("文本已改变: $value");
                      },
                      keyboardType: TextInputType.text,
                      textInputAction: TextInputAction.search,
                      onSubmitted: (value) {
                        _search(value);
                      },
                      controller: controller,
                      textAlign: TextAlign.center,
                      style: TextStyle(
                        color: Colors.black, // 文本颜色
                        fontSize: 12.0, // 字体大小
                      ),
                      decoration: InputDecoration(
                        focusedBorder: OutlineInputBorder(
                          borderSide: BorderSide(
                              color: Colors.white, width: 0), // 激活状态下的边框颜色和宽度
                          borderRadius: BorderRadius.circular(10.0), // 设置圆角边框半径
                        ),
                        enabledBorder: OutlineInputBorder(
                          borderSide: BorderSide(
                              color: Colors.white, width: 0), // 激活状态下的边框颜色和宽度
                          borderRadius: BorderRadius.circular(10.0), // 设置圆角边框半径
                        ),
                        filled: true,
                        fillColor: Color(0xfff5f5f5),
                        hintText: '搜索',
                        hintStyle:
                            TextStyle(fontSize: 14, color: Color(0xff999999)),
                        border: InputBorder.none,
                      ),
                    ),
                  ),
                  Positioned(
                    top: 9,
                    // 第一个层叠的小部件
                    left: -40,
                    right: 0,
                    child:
                        Icon(Icons.search, size: 20, color: Color(0xff999999)),
                  )
                ],
              ),

                 if (kIsWeb)
                      Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Image.asset('static/qidai.png',
                          width: 250,
                          ) 
                          ],
                        ),
                        
                      if (!kIsWeb)

              Obx(() => Column(
                    children: [
                      for (var item in list)
                        GestureDetector(
                          onTap: () async{
                             Get.toNamed('/chat/msg?userid=${item.userID}&name=${item.nickName}');
                          },
                          child: Container(
                            padding: EdgeInsets.only(bottom: 15, top: 15),
                            decoration: BoxDecoration(
                                border: Border(
                                    bottom:
                                        BorderSide(color: Color(0XFFDDDDDD)))),
                            child: Row(
                              children: [
                                CircleAvatar(
                                    radius: 16,
                                    backgroundImage:
                                        NetworkImage('${item.faceUrl}')),
                                SizedBox(
                                  width: 10,
                                ),
                                Text(
                                  '${item.nickName}',
                                  style: TextStyle(
                                      fontSize: 14, color: Color(0XFF333333)),
                                )
                              ],
                            ),
                          ),
                        )
                    ],
                  )),

              // GestureDetector(
              //   onTap: (){
              //     print('object');
              //     Get.toNamed('/chat/book');
              //   },
              //   child: Container(
              //   padding: EdgeInsets.only(bottom: 15,top: 15),
              //   decoration: BoxDecoration(
              //     border: Border(
              //       bottom: BorderSide(
              //         color: Color(0XFFDDDDDD)
              //       )
              //     )
              //   ),
              //   child: Row(
              //     children: [
              //        CircleAvatar(
              //         radius: 16,
              //         backgroundImage:AssetImage('static/aaa.png')
              //       ),
              //       SizedBox(width: 10,),
              //       Text('DDD',style: TextStyle(fontSize: 14,color: Color(0XFF333333)),)
              //     ],
              //   ),
              // ),
              // )
            ],
          ),
          Positioned(
            child: Container(
              height: 50,
              alignment: Alignment.topCenter,
              color: Color(0XFFFFFFFF),
              child: Image.asset(
                'static/images/hometop.png',
                fit: BoxFit.fitWidth,
                width: double.infinity,
              ),
            ),
          ),
          Positioned(
              top: totalHeight,
              left: 0,
              right: 0,
              child: Align(
                child: Text('通讯录',
                    style: TextStyle(fontSize: 16, color: Color(0XFF333333))),
              )),
          Positioned(
              top: totalHeight,
              right: 15,
              child: GestureDetector(
                  onTap: () async {

                                final bools =  await Get.toNamed('/chat/add');
                                if(bools){
                                    _getFriendList();
                                }
                  },
                  child: Image.asset(
                    'static/images/youadd.png',
                    width: 18,
                    fit: BoxFit.fitWidth,
                  ))),
        ],
      ),
    );
  }
}


// import 'package:flutter/material.dart';
// import 'package:get/get.dart';

// class CommunicationLIst extends StatelessWidget {
//   @override
//   Widget build(BuildContext context) {
//     return Scaffold(
//            appBar: AppBar(
//             backgroundColor: Color(0xffffffff),
//             title: Text('平台公告'),
//             centerTitle: true
//           ),
//     );
//   }
// }
 